package component {
	
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class Text extends TextField {
		
		private static const BLACK:Array = [new GlowFilter(0, 1, 2, 2, 3)];
		private static const WHITE:Array = [new GlowFilter(0xFFFFFF, 0.5, 5, 5, 3)];
		private static const YELLOW:Array =[new GlowFilter(0xFFFF00,1,5,5,3)];
		private static const BLUE:Array =[new GlowFilter(0xC2FFFE,1,5,5,3)];
		public var data:Object;
		
		public function Text(properties:Object = null) {
			mouseWheelEnabled = false;
			edit = false;
			_format.leading = 4;
			defaultTextFormat = _format;
			text = "";
			for(var key:String in properties)this[key] = properties[key];
			filters = _format.color?BLACK:WHITE;
		}
		
		public override function set text(value:String):void {
			super.text = value;
			if(edit && wordWrap){
			}
			else {
				if(!edit && !wordWrap)super.width = textWidth + 5;
				height = textHeight + 5;
			}
			
		}
		
		//    public override function get htmlText():String{
		//      return StringFilter.replace(super.htmlText);
		//    }
		
		public override function set htmlText(value:String):void{
			super.htmlText = value;
			if(edit && wordWrap){
			}
			else {
				if(!edit && !wordWrap)super.width = textWidth + 5;
				height = textHeight + 5;
			}
		}
		
		public function get edit():Boolean {return type == TextFieldType.INPUT;}
		public function set edit(value:Boolean):void {
			type = value?TextFieldType.INPUT:TextFieldType.DYNAMIC;
			mouseEnabled = value;
			selectable = value;
		}
		
		private var _format:TextFormat = new TextFormat("Tahoma", 12, 0xFFFFFF);
		public function set format(value:Object):void {
			for(var key:String in value){
				if(_format.hasOwnProperty(key)){
					_format[key] = value[key];
				}
			}
			defaultTextFormat = _format;
			setTextFormat(_format);
			text = text;
		}
		
		private var _width:int;
		public override function set width(value:Number):void {
			super.width = value;
			wordWrap = true;
			multiline = true;
			_width = value;
		}
	
	}
}